#type vertex
#version 330 core
// 顶点属性
layout (location = 0) in vec3 aPos; // 坐标
layout (location = 1) in vec2 aTex; // 纹理坐标

// 输出到fragment shader的纹理坐标
out vec2 FragTex;

uniform mat4 _model;        // 模型变换矩阵
uniform mat4 _view;         // 观察矩阵
uniform mat4 _projection;   // 投影矩阵

void main() {
    FragTex = aTex;
    gl_Position = vec4(aPos, 1.0);
    // 实现三个矩阵变换
    gl_Position = _projection * _view * _model * vec4(aPos, 1.0);
}

#type fragment
#version 330 core

in vec2 FragTex;

uniform sampler2D _outside;
uniform sampler2D _inside;

// 鼠标坐标
uniform vec2 _mousepos;
// xray范围
uniform float _range;

out vec4 FragOut;

void main() {
    FragOut = vec4(1.0);
    // 表层纹理
    FragOut = texture(_outside, FragTex);
    // 里层纹理
    FragOut = texture(_inside, FragTex);
    // 实现X-Ray (提示: 可以使用内建变量 gl_FragCoord 获取当前 fragment 所在的窗口坐标)
    vec2 mousePos = vec2(_mousepos.x, _mousepos.y);
    float dis = distance(gl_FragCoord.xy, mousePos);
    // 无平滑过渡
    FragOut = dis < 100 ? texture(_inside, FragTex) : texture(_outside, FragTex);
    // 平滑过渡
    float x = dis / _range;
    x = x - 1.0;
    FragOut = mix(texture(_outside, FragTex), texture(_inside, FragTex), 1.0 / (1.0 + exp(15 * x)));
}
